#include "set.h"
#include "ui_set.h"

set::set(Gobang_Network *gn, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::set)
{
    ui->setupUi(this);

    this->gn = gn;

    QFile file(path);//参数就是文件的路径

    if (!file.open(QIODevice::ReadOnly)) {

        QDir().mkpath(QFileInfo(path).absoluteDir().path());

        this->write_ip("124.71.7.74");
    }

    file.open(QIODevice::ReadOnly);
    char *ip = new char[QString("888.888.888.888").length()];
    file.read(ip, QString("888.888.888.888").length());

    this->gn->t->host.clear();
    this->gn->t->host = QString::fromUtf8(ip);

    this->ui->lineEdit_ip->setText(this->gn->t->host);
}

set::~set()
{
    delete ui;
}

void set::write_ip(QString ip)
{
    QFile file(path);

    file.open(QIODevice::WriteOnly);

    QByteArray ba = ip.toLatin1();

    file.write(ba.data(), ba.length());
    file.close();
}

void set::setSize(int x, int y, int w, int h)
{
    this->ui->verticalLayoutWidget->setGeometry(x,y,w,h);
}

void set::on_pushButton_clicked()
{
    write_ip(ui->lineEdit_ip->text());

    QMessageBox::information(this, "提示", "设置成功", QMessageBox::Yes, QMessageBox::Yes);
}
